package com.qf.service;

import com.alibaba.druid.util.StringUtils;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.mapper.DtsTopicMapper;
import com.qf.pojo.DtsTopic;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @author sunyamei
 * @version V1.0
 * @Project javase2203
 * @Package com.qf.service
 * @Description:
 * @Date 2022/7/31 14:24
 */
@Service
public class TopicServiceImpl implements  TopicService {

   @Autowired
   private DtsTopicMapper topicMapper;


    @Override
    public IPage<DtsTopic> queryByPage(String title, String subtitle, Integer page, Integer limit, String sort, String order) {

        //创建分页对象
        IPage<DtsTopic> ipage = new Page<>(page, limit);


        //创建查询条件对象
        QueryWrapper<DtsTopic> queryWrapper = new QueryWrapper<>();

        //判断条件是否为空
        if (!StringUtils.isEmpty(title)){
            queryWrapper.eq("title", title);
        }
        if (!StringUtils.isEmpty(subtitle)){
            queryWrapper.eq("subtitle", subtitle);
        }


        //排序
        if (!StringUtils.isEmpty(sort) && !StringUtils.isEmpty(order) ){
            if (order.equalsIgnoreCase("asc")){
                queryWrapper.orderByAsc(sort);
            } else{
                 queryWrapper .orderByDesc(sort);
                }
            }
        IPage<DtsTopic> topicIPage = topicMapper.selectPage(ipage, queryWrapper);
        return  topicIPage;
    }

    }

